<template>
  <!-- 职位列表 -->
  <div class="positionList">
    <head-usual :title="title" :to="to"></head-usual>
      <div class="body-all" v-if="userType==1">
            <!-- 排序筛选-->
          <div class="body-all">
          <!-- 类型分类 -->
            <div class="body">
                <div class="area nav" @click="switchFilter('industrycla')">
                    <span>行业类型</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-1" v-model="showIndustrycla" position="top" popup-transition="popup-fade">
                    <ul class="body-tanchu">
                        <li class="area-li" >
                            <a @click="handleFilter('industrycla',0)" v-bind:class="{ active: ''==searchCondition.industrycla }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_Hyfl" :key="index" >
                            <a @click="handleFilter('industrycla',item.id)" v-bind:class="{ active: item.name==searchCondition.industrycla }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
                <div class="major nav" @click="switchFilter('nature')">
                    <span>工作性质</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-2" v-model="showNature" position="top" popup-transition="popup-fade">
                    <ul class="body-tanchu">
                        <li class="area-li" >
                            <a @click="handleFilter('nature','')" v-bind:class="{ active: 0==searchCondition.nature }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_JobNature" :key="index" >
                            <a @click="handleFilter('nature',item.id)" v-bind:class="{ active: item.id==searchCondition.nature }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
                <div class="major-classify nav" @click="switchFilter('experience')">
                    <span>工作经验</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-3" v-model="showExperience" position="top" popup-transition="popup-fade" >
                    <ul class="body-tanchu">
                    <li class="area-li" >
                            <a @click="handleFilter('experience','')" v-bind:class="{ active: 0==searchCondition.experience }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_JobExperience" :key="index" >
                            <a @click="handleFilter('experience',item.id)" v-bind:class="{ active: item.id==searchCondition.experience }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
            </div>
          </div>
            <!-- 排序 -->
          <div class="classify">
            <div v-bind:class="(searchCondition.sort.indexOf('all') != -1?'active ':'')+' classify-item'" @click="handleRank('all')">综合  {{searchCondition.sort=="all1"?'↓':'↑'}}</div>
            <div v-bind:class="(searchCondition.sort.indexOf('t') != -1?'active ':'')+' classify-item'" @click="handleRank('t')">发布时间 {{searchCondition.sort=="t1"?'↓':'↑'}}</div>
            <div v-bind:class="(searchCondition.sort.indexOf('b') != -1?'active ':'')+' classify-item'" @click="handleRank('b')">投递人数 {{searchCondition.sort=="b1"?'↓':'↑'}}</div>
          </div>
          <!-- 职位列表 -->
          <div class="position-list" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="0">
              <router-link class="position-item" :to="'/jobs/detail/'+item.id" v-for="(item,index) in pagedListData" :key="index" active-class="active-p">
                  <p class="p1">
                    <span>{{item.name}}  {{item.nature}}</span>  <span>{{item.lowSalary}} K</span>
                  </p>
                  <p class="p2">
                      <span class="p2-1">{{item.provinces}}</span><span class="fenge"></span>
                      <span class="p2-2">{{item.degree}}</span><span class="fenge"></span>
                      <span class="p2-3">{{item.experience}}</span><span class="fenge"></span>
                      <span class="p2-4">{{item.addtime}}</span>
                  </p>
                  <p class="p3">
                      <span v-for="(tag,index2) in item.Arr_tags" :key="index2">{{tag}}</span>
                  </p>
                  <P class="p4"></P>
                  <dl class="dl5">
                      <dt><img :src="item.Publisher.headportrait"/></dt>
                      <dd>
                          <p>{{item.Publisher.name}}</p>
                          <p>
                              <span>{{item.Publisher.workinglife}}人</span>
                              <span class="fenge02"></span>
                              <span>{{item.Publisher.industry}}</span>
                          </p>
                      </dd>
                  </dl>
              </router-link>
              <div v-show="loading" class="page-infinite-loading">
                  <mt-spinner type="fading-circle"></mt-spinner>
                  加载中...
              </div>
              <div v-show="allLoaded" class="page-infinite-data">亲！别拉了我是有底线的</div>
          </div>
      </div>
      <div class="body-all" v-else>
            <!-- 排序筛选-->
          <div class="body-all">
          <!-- 类型分类 -->
            <div class="body">
                <div class="area nav" @click="switchFilter('role')">
                    <span>行业角色</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-1" v-model="showRole" position="top" popup-transition="popup-fade">
                    <ul class="body-tanchu">
                        <li class="area-li" >
                            <a @click="handleFilter('role',0)" v-bind:class="{ active: ''==searchCondition.role }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_Role" :key="index" >
                            <a @click="handleFilter('role',item.id)" v-bind:class="{ active: item.id==searchCondition.role }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
                <div class="major nav" @click="switchFilter('nature')">
                    <span>工作性质</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-2" v-model="showNature" position="top" popup-transition="popup-fade">
                    <ul class="body-tanchu">
                        <li class="area-li" >
                            <a @click="handleFilter('nature','')" v-bind:class="{ active: 0==searchCondition.nature }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_JobNature" :key="index" >
                            <a @click="handleFilter('nature',item.id)" v-bind:class="{ active: item.id==searchCondition.nature }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
                <div class="major-classify nav" @click="switchFilter('lowSalary')">
                    <span>职位薪资</span>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shang-copy-copy"></use>
                    </svg>
                </div>
                <mt-popup class="tlm-popup tlm-popup-3" v-model="showlowSalary" position="top" popup-transition="popup-fade" >
                    <ul class="body-tanchu">
                    <li class="area-li" >
                            <a @click="handleFilter('lowSalary','')" v-bind:class="{ active: 0==searchCondition.lowSalary }">不限</a>
                        </li>
                        <li v-for="(item,index) in this.$store.state.filter_LowSalary" :key="index" >
                            <a @click="handleFilter('lowSalary',item.id)" v-bind:class="{ active: item.id==searchCondition.lowSalary }">{{item.name}}</a>
                        </li>
                    </ul>
                </mt-popup>
            </div>
          </div>
            <!-- 排序 -->
          <div class="classify">
            <div v-bind:class="(searchCondition.sort.indexOf('all') != -1?'active ':'')+' classify-item'" @click="handleRank('all')">综合  {{searchCondition.sort=="all1"?'↓':'↑'}}</div>
            <div v-bind:class="(searchCondition.sort.indexOf('p') != -1?'active ':'')+' classify-item'" @click="handleRank('p')">好评率 {{searchCondition.sort=="p1"?'↓':'↑'}}</div>
            <div v-bind:class="(searchCondition.sort.indexOf('h') != -1?'active ':'')+' classify-item'" @click="handleRank('h')">点击量 {{searchCondition.sort=="h1"?'↓':'↑'}}</div>
          </div>
          <!-- 职位列表 -->
          <div class="position-list" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="0">
              <div class="position-item user-position"  v-for="(item,index) in pagedListData" :key="index" active-class="active-p">
                  <router-link class="position-item user-position" :to="'m/'+item.uid" active-class="active-p">
                   <div class="awatar-box">
                    <img :src="item.headportrait.indexOf('/Res')==-1?item.headportrait:'http://www.zhugongzhe.com'+item.headportrait"/>
                  </div>
                  <div class="position-right">
                    <p class="p-1">{{item.name}}<span>{{item.position}}</span></p>
                    <p class="p-2"><span>工作性质：{{item.positionType}}</span><span>期望城市：{{item.city}}</span><span>职位薪资：<i>{{item.monthlySalary}}</i></span></p>
                    <p  class="p-3">补充说明：<span>{{item.description}}</span></p>
                  </div>
                  </router-link>
                  <!-- <p class="p1">
                    <span>{{item.name}}  {{item.nature}}</span>  <span>{{item.lowSalary}} K</span>
                  </p>
                  <p class="p2">
                      <span class="p2-1">{{item.provinces}}</span><span class="fenge"></span>
                      <span class="p2-2">{{item.degree}}</span><span class="fenge"></span>
                      <span class="p2-3">{{item.experience}}</span><span class="fenge"></span>
                      <span class="p2-4">{{item.addtime}}</span>
                  </p>
                  <p class="p3">y
                      <span v-for="(tag,index2) in item.Arr_tags" :key="index2">{{tag}}</span>
                  </p>
                  <P class="p4"></P>
                  <dl class="dl5">
                      <dt><img :src="item.Publisher.headportrait"/></dt>
                      <dd>
                          <p>{{item.Publisher.name}}</p>
                          <p>
                              <span>{{item.Publisher.workinglife}}人</span>
                              <span class="fenge02"></span>
                              <span>{{item.Publisher.industry}}</span>
                          </p>
                      </dd>
                  </dl> -->
             
              </div>
              <div v-show="loading" class="page-infinite-loading">
                  <mt-spinner type="fading-circle"></mt-spinner>
                  加载中...
              </div>
              <div v-show="allLoaded" class="page-infinite-data">亲！别拉了我是有底线的</div>
          </div>
      </div>
    <footer-total></footer-total>
  </div>
</template>
<script>
// import headUsual from "@/pages/components/headUsual";
// import footerTotal from '@/pages/components/footerTotal'
import { GetPagedList,GetRecruitList } from "@/api/jobs";
export default {
  data() {
    return {
      title: "职位列表",
      to:'/',
      pagedListData: [],
      showNature: false,
      showIndustrycla: false,
      showExperience: false,
      showlowSalary:false,
      showRole:false,
      searchCondition: {
        area: "",
        experience: 0,
        industrycla: 0,
        nature: 0,
        lowSalary:0,//薪资
        role:0,//行业角色
        pageindex: 1,
        sort: "all1"
      },
      userType:1,
      loading: false, //是否显示加载中
      allLoaded: false, //加载完毕
      totalpage: 0 //总页码
    };
  },
  created() {
    this.userType=this.$store.state.userinfo.type;
    this._getPagedList();
    
  },
  methods: {
    //操作排序
    handleRank(cmd) {
      if (this.searchCondition.sort.indexOf("1") != -1) {
        this.searchCondition.sort = cmd + "2";
      } else {
        this.searchCondition.sort = cmd + "1";
      }
      this._getPagedList();
    },
    switchFilter(type) {
      //顶部切换 筛选条件
      switch (type) {
        case "nature":
          {
            this.showNature = true;
            this.showIndustrycla = false;
            this.showExperience = false;
             this.showlowSalary = false;
            this.showRole = false;
          }
          break;
        case "industrycla":
          {
            this.showNature = false;
            this.showIndustrycla = true;
            this.showExperience = false;
          }
          break;
        case "experience":
          {
            this.showNature = false;
            this.showIndustrycla = false;
            this.showExperience = true;
          }
          break;
         case "role":
          {
            this.showNature = false;
            this.showlowSalary = false;
            this.showRole = true;
          }break;
           case "lowSalary":
          {
            this.showNature = false;
            this.showlowSalary = true;
            this.showRole = false;
          }break;
        default:
          break;
      }
    },
    handleFilter(type, value) {
      switch (type) {
        case "nature":
          {
            this.searchCondition.nature = value;
          }
          break;
        case "industrycla":
          {
            this.searchCondition.industrycla = value;
          }
          break;
        case "experience":
          {
            this.searchCondition.experience = value;
          }
          break;
        case "role":
          {
            this.searchCondition.role = value;
          }
          break;
            case "lowSalary":
          {
            this.searchCondition.lowSalary = value;
          }
          break;
        default:
          break;
      }
      this.showNature = false;
      this.showIndustrycla = false;
      this.showExperience = false;
      this.showlowSalary=false;
      this.showRole=false;
      this._getPagedList();
    },
    loadMore() {
      //分页加载更多
      if (this.searchCondition.pageindex >= this.totalpage) {
        this.allLoaded = true;
        return;
      }
      this.loading = true;
      setTimeout(() => {
        this.searchCondition.pageindex++;
        if(this.userType==1){
          GetPagedList(
                this.searchCondition
              ).then(res => {
                if (res.StatusCode === 200) {
                  this.pagedListData = this.pagedListData.concat(res.Data);
                }
              });
        }
        this.loading = false;
      }, 1000);
    },
    // 获取数据
    _getPagedList() {
      this.$indicator.open();
      this.searchCondition.pageindex=1;
      if(this.userType==1){
        GetPagedList(
              this.searchCondition
            ).then(res => {
              if (res.StatusCode === 200) {
                this.pagedListData = res.Data;
                this.totalpage = res.TotalPage;
                this.$indicator.close();
              }
              console.log(this.pagedListData);
            });
      }
      else{
         GetRecruitList(
              this.searchCondition
            ).then(res => {
              if (res.StatusCode === 200) {
                this.pagedListData = res.Data;
                this.totalpage = res.TotalPage;
                this.$indicator.close();
              }
            });
      }
   
    }
  }
};
</script>

<style scoped lang="scss">

.body-all {
  position: relative;
}
/* 分类*/
.body {
  width: 100%;
  height: 44px;
  display: flex;
  border-top: 1px solid #f4f4f4;
  text-align: center;
  //分类下每一个选项
  .nav {
    width: 33.3%;
    border-right: 1px solid #f4f4f4;
    // border-bottom: 1px solid #ccc;
    line-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    span {
      font-size: 14px;
      color: #333333;
    }
    .icon{
      font-size: 18px;
    }
    .icon-active {
      color: #fd4f00;
    }
  }
  // 角色分类右边框消失
  .major-classify {
    border-right: none !important;
  }
}
.body-tanchu {
  width: 100%;
  background: white;
  padding: 15px 12px 2px 12px;
  display: flex;
  flex-wrap: wrap;
}
.body-tanchu > li {
  display: flex;
  text-align: center;
  flex:0 0 33.3%;
  margin-bottom: 10px;
  justify-content: center;
  
    a{
       width: 115px;
      height: 34px;
      line-height: 34px;
        overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
      border: 1px solid #eeeeee;

    }
  
}
.popup-layer {
  width: 414px;
  background-color: #fff;
  padding: 0;
  margin: 0;
  left: 50%;
  position: absolute;
}
// 弹出阴影层
.body-all > .v-modal {
  width: 100%;
  height: 73%;
}
.hidden {
  width: 100%;
  z-index: 99999;
  height: 88px;
  position: absolute;
  top: -44px;
  left: 0;
  background-color: white;
  opacity: 0;
}
.active {
  border-color: #fd4f00 !important;
  color: #fd4f00 !important;
}
/* 3个排序 */
.classify {
  width: 100%;
  height: 42px;
  background: #f9f9f9;
  display: flex;
  align-items: center;
  text-align: center;
  border-bottom: 1px solid #eeeeee;
  .classify-item {
    width: 33.3%;
    font-size: 14px;
    color: #282828;
  }
  .active {
    color: #fd4f00 !important;
  }
}
// 职位信息
.position-list {
  overflow: hidden;

  .position-item {
    display: block;
    padding-left: 11px;
    padding-right: 11px;
    padding-bottom: 15.3px;
    border-bottom: 8.3px solid #f4f4f4;
    // 第一行
    .p1 {
      overflow: hidden;
      margin-bottom: 12px;
      margin-top: 16px;
      > :first-child {
        color: #282828;
        font-size: 16px;
        display: block;
        float: left;
      }
      .p1-bolder {
        color: #282828;
      }
      > :last-child {
        color: #fd4f00;
        font-size: 16px;
        display: block;
        float: right;
        margin-right: 12px;
      }
    }
    // 第二行
    .p2 {
      overflow: hidden;
      margin-bottom: 13px;
      display: flex;
      align-items: center;
       font-size: 14px;
      > span {
        color: #666666;
        font-size: 14px;
      }
      .p2-1 {
        margin-right: 9px;
      }
      .p2-2 {
        margin-right: 9px;
      }
      .p2-3 {
        margin-right: 9px;
      }
      .fenge {
        width: 1px;
        height: 12px;
        background: #666666;
        margin-right: 10px;
      }
      .p2-4 {
        float: right;
        margin-right: 12px;
      }
    }
    // 第三行
    .p3 {
      > span {
        font-size: 10px;
        color: #999999;
        padding: 5.3px 8.16px;
        border: 1px solid transparent;
        background: #f3f3f3;
        display: inline-block;
        margin-right: 11px;
      }
    }
    //第四行虚线
    .p4 {
      height: 0px;
      margin: 12px auto;
      border: 1px dashed #eeeeee;
    }
    // 第五个dl列表
    .dl5 {
      overflow: hidden;
      height: 55px;
      margin: 0;
      // 图片设置
      > dt {
        width: 40px;
        height: 40px;
        float: left;
        > img {
          width: 40px;
          height: 40px;
          display: block;
        }
      }
      > dd {
        float: left;
        margin-left: 14px;

        > p {
          color: #999999;
          font-size: 14px;
          margin: 0;
        }
        :first-child {
          color: #282828;
          font-size: 14px;
          margin-bottom: 3px;
        }
        :last-child {
          overflow: hidden;
          > span {
            margin-bottom: 0;
            font-size: 12px;
            color: #999999;
            display: block;
            float: left;
          }
          .fenge02 {
            width: 1px;
            height: 11px;
            border: 1px solid #999999;
            margin-top: 3.51px;
            margin-left: 11px;
            margin-right: 11px;
          }
        }
      }
    }
  }
  .user-position{
    display: flex;
    padding: 16px;
    .awatar-box{
      flex: 0 0 18%;
      width: 76.44px;
      height: 76.44;
      line-height: 76.44px;
      overflow: hidden;
      img{
        width: 100%;
        height: auto;
      }
    }
    .position-right{
      margin-left: 10px;
      flex: 0 0 75%;
      .p-1{
        font-size: 14px;
        color:#666;
        position: relative;
        span{
          color:#3887fe;
          padding-left: 15px;
          &::before{
            content: "";
            width: 2px;
            height: 10px;
            background: #3887fe;
            position: absolute;
            top:50%;
            margin-top:-5px;
            margin-left: -6px;
          }          
        }
      }
      .p-2{
        margin-top:10px;
        color:#666;
        font-size: 14px;
        overflow: hidden;
         display: flex;
         flex-wrap: wrap;
        span{
         
          flex: 0 0 50%;
          i{
            font-style: normal;
            color: red;
          }
        }
      }
      .p-3{
        font-size: 14px;
        color:#666;
        margin-top: 4px;
          span{
            color:#999;
          }
      }
    }
  }
}
.salary-add {
  color: #fd4f00 !important;
}
// 点击过后颜色发生改变
.active-p .p1>:last-child{
  color:#999999;
}
</style>
